home *** CD-ROM | disk | FTP | other *** search
- program xFighterDemo2;
-
- { 3d GrafSys Demo Program}
- { Vers. 1.1 }
- { (c) 1992 by Christian Franz }
-
- { This program demonstates the use of the grafsys for simple animation using }
- { the screenObjects }
-
- { note that you can also move the eye by pressing the corresponding keys }
-
- uses
- (* Matrix, Transformations, Data3D,*)
- Grafsys, Screen3D;
-
- const
- theWindowID = 400;
- degree = 0.01745329; (* π/180 *)
-
- var
- theWindow: WindowPtr;
- theInt: INTEGER;
- thePort: Graf3DPtr;
- theMaster: Graf3DPtr;
- Pyramid, Cube, xFighter: GrafObjPtr;
- theEvent: EventRecord;
- dx, dy, dz: integer;
- r, PR, VR: Rect;
- SO: ScreenObjPtr;
- dummy: boolean;
-
-
- procedure getmouserot (var dx, dy, dz: integer);
-
- var
- thePoint: point;
-
- begin
- GetMouse(thePoint);
- dx := 0;
- dy := 0;
- dz := 0;
- if (thePoint.h < thePort^.center.h) and (thePoint.v < thePort^.center.v) then (* mouse in quadrant 1 -> xrot*)
- begin
- dx := 5;
- end;
- if (thePoint.h > thePort^.center.h) and (thePoint.v < thePort^.center.v) then (* mouse in quadrant 2 -> yrot*)
- begin
- dy := 5;
- end;
- if (thePoint.h > thePort^.center.h) and (thePoint.v > thePort^.center.v) then (* mouse in quadrant 3 -> zrot*)
- begin
- dz := 5;
- end;
- if (thePoint.h < thePort^.center.h) and (thePoint.v > thePort^.center.v) then (* mouse in quadrant 4 -> idle*)
- begin
- end;
- if button then
- begin
- dx := -dx;
- dy := -dy;
- dz := -dz;
- end;
- end;
-
- const
- closer = 58; (* option Key *)
- further = 55; (* command key *)
- haltkey = 76; (* keypad enter *)
-
- leftArrow = $7B;
- rightArrow = $7C;
- upArrow = $7E;
- downArrow = $7D;
-
- num1 = $53;
- num2 = $54;
-
- var
-
- theKeys: KeyMap;
- theta, phi: integer;
- pitch: integer;
- update: boolean;
-
- begin
- InitCursor;
- theWindow := GetNewWindow(theWindowID, nil, Pointer(-1));
- SetPort(theWindow); (* draw in this window *)
-
- MoveTo(10, 10);
- DrawString('3D GrafSys. Object:x-Fighter (Clip/persp). (C) 1992 by CF.');
- InitGrafSys;
- NewGrafport(theWindow^.portRect, thePort);
-
- MoveTo(10, 25 * 15);
- DrawString('Descr. : Press Keypad-Enter to stop');
- MoveTo(10, 26 * 15);
- DrawString(' Option to zoom closer');
- MoveTo(10, 27 * 15);
- DrawString(' Command to move further away');
- MoveTo(10, 28 * 15);
- DrawString(' Move mouse into fighter to rotate it');
-
- PR := theWindow^.PortRect;
- SetRect(VR, thePort^.center.h - 0, thePort^.center.v - 100, thePort^.center.h + 220, thePort^.center.v + 100);
- r := VR;
- for dx := 1 to 3 do
- begin
- InsetRect(r, -2, -2);
- FrameRect(r);
- end;
- SetView(PR, VR);
- SetCenter(thePort^.center.h + 120, thePort^.center.v);
-
- xFighter := GetNewNamedObject('theFighter');
-
- SetEye(true, 0, 0, -200, 0 * degree, 0 * degree, 0 * degree, 1.54079633, true);
- ObjTranslate(xFighter, 0, 0, 0);
- ObjRotate(xFighter, 0 * degree, 0 * degree, 0);
- SetAutoErase(xFighter, true);
- SO := NewScreenObject;
- AttachScreenObject(SO, xFighter); (* Link for all changes *)
- CalcScreenObject(xFighter, TRUE);
- DrawScreenObject(xFighter);
- phi := 0;
- theta := 0;
- pitch := 0;
-
- repeat
- GetMouseRot(dx, dy, dz);
- if (dx + dy + dz <> 0) or (theKeys[closer]) or (theKeys[further]) or update then
- DrawScreenObject(xFighter); (* draw Object *)
- update := false;
- ObjRotate(xFighter, dx * degree, dy * degree, dz * degree);
-
- GetKeys(theKeys);
- if theKeys[further] then
- ObjTranslate(xFighter, 0, 0, 10);
- if theKeys[closer] then
- ObjTranslate(xFighter, 0, 0, -10);
- if theKeys[leftArrow] then
- begin
- theta := (theta + 5) mod 355;
- SetEye(true, 0, 0, -200, phi * degree, theta * degree, pitch * degree, 1.54079633, true);
- update := true;
- end;
-
- if theKeys[rightArrow] then
- begin
- theta := (theta - 5) mod 355;
- SetEye(true, 0, 0, -200, phi * degree, theta * degree, pitch * degree, 1.54079633, true);
- update := true;
- end;
-
- if theKeys[upArrow] then
- begin
- phi := (phi + 5) mod 355;
- SetEye(true, 0, 0, -200, phi * degree, theta * degree, pitch * degree, 1.54079633, true);
- update := true;
- end;
-
- if theKeys[downArrow] then
- begin
- phi := (phi - 5) mod 355;
- SetEye(true, 0, 0, -200, phi * degree, theta * degree, pitch * degree, 1.54079633, true);
- update := true;
- end;
-
- if theKeys[num1] then
- begin
- pitch := (pitch + 5) mod 355;
- SetEye(true, 0, 0, -200, phi * degree, theta * degree, pitch * degree, 1.54079633, true);
- update := true;
- end;
-
- if theKeys[num2] then
- begin
- pitch := (pitch - 5) mod 355;
- SetEye(true, 0, 0, -200, phi * degree, theta * degree, pitch * degree, 1.54079633, true);
- update := true;
- end;
-
- CCalcScreenObject(xFighter, TRUE);
- until theKeys[haltkey];
- repeat
- dummy := GetNextEvent(everyEvent, theEvent);
- until theevent.what = mousedown;
- end.